package com.design.blog.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.design.blog.dao.ArticleMapper;
import com.design.blog.dao.CategoryMapper;
import com.design.blog.model.Article;
import com.design.blog.model.Category;
import com.design.blog.model.vo.CategoryVO;
import com.design.blog.service.ICategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * @author hxg
 * @date 2022-02-28
 *  服务实现类
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    @Resource
    private ArticleMapper articleMapper;

	@Override
	public IPage<Category> selectCategoryPage(IPage<Category> page, CategoryVO category) {
		return page.setRecords(baseMapper.selectCategoryPage(page, category));
	}

    @Override
    public List<Category> getCategorys() {
        LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>();
        //wrapper.select(Category::getCategoryName);
        //wrapper.groupBy(Category::getCategoryName);
        List<Category> categories = categoryMapper.selectList(wrapper);
        return categories;
    }

    @Override
    public List<Article> getCategoryArticles(Long id) {
        LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Article::getCategoryId, id);
        List<Article> categorieArticle = articleMapper.selectList(wrapper);
        return categorieArticle;
    }

}
